package com.vanzo.ui;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.vanzo.Tpplication;
import com.vanzo.instruction.Instruction;
import com.vanzo.util.LogUtil;

/**
 * Created by tisen on 2018/3/8.
 */

public class BaseActivity extends AppCompatActivity {

    protected Tpplication tpplication;
    protected Instruction instruction;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtil.put(this, "onCreate", LogUtil.WARN);
        tpplication = (Tpplication) getApplication();
        instruction = tpplication.getInstruction();
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        getSupportActionBar().hide();
        getWindow().setStatusBarColor(Color.TRANSPARENT);
        getWindow().setNavigationBarColor(Color.TRANSPARENT);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && Build.VERSION.SDK_INT >= 19) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
//                            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
//                            View.SYSTEM_UI_FLAG_FULLSCREEN |
                            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        LogUtil.put(this, "onStart", LogUtil.WARN);
    }

    @Override
    protected void onResume() {
        super.onResume();
        LogUtil.put(this, "onResume", LogUtil.WARN);
        instruction.reStart();
        if (!instruction.isPower()&&isShowTip()) {
            Toast.makeText(this, "请在快捷开关中打开对讲", Toast.LENGTH_LONG).show();
        }
    }

    public boolean isShowTip() {
        return true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        LogUtil.put(this, "onPause", LogUtil.WARN);
        instruction.interrupt();
    }

    @Override
    protected void onDestroy() {
        LogUtil.put(this, "onDestroy", LogUtil.WARN);
        super.onDestroy();
    }
}
